package com.example.demo.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * Copyright (C), 2015-2019
 * FileName: TestService
 * Author:   MRC
 * Date:     2019/12/29 10:03
 * Description:
 * History:
 */
@Service
public class TestService {

    @Autowired
    private RestTemplate restTemplate;

    /**
     * @return java.lang.String
     * @Author MRC
     * @Description //TODO 将ADD请求进行分摊
     * @Date 22:22 2019/12/26
     * @Param [] HystrixCommand 注解 如果这个服务挂掉了 就返回异常
     **/
    @HystrixCommand(fallbackMethod = "serviceCallBack")
    public String add() {
        return restTemplate.getForEntity("http://eureka-client/list", String.class).getBody();
    }


    public String serviceCallBack() {
        return "error";
    }


}